﻿using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Identity.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class ChangeMessageStruct : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropPrimaryKey(
                name: "PK_UserOfflineMessage",
                table: "UserOfflineMessage");

            migrationBuilder.DropColumn(
                name: "IsSent",
                table: "UserOfflineMessage");

            migrationBuilder.DropColumn(
                name: "RecipientId",
                table: "UserOfflineMessage");

            migrationBuilder.RenameTable(
                name: "UserOfflineMessage",
                newName: "T_UserOfflineMessage");

            migrationBuilder.RenameColumn(
                name: "SendTime",
                table: "T_UserOfflineMessage",
                newName: "CreateTime");

            migrationBuilder.AddPrimaryKey(
                name: "PK_T_UserOfflineMessage",
                table: "T_UserOfflineMessage",
                column: "MessageId")
                .Annotation("SqlServer:Clustered", true);

            migrationBuilder.CreateTable(
                name: "T_UnsentUser",
                columns: table => new
                {
                    UnsentId = table.Column<long>(type: "bigint", nullable: false),
                    UserId = table.Column<long>(type: "bigint", nullable: false),
                    IsSent = table.Column<bool>(type: "bit", nullable: false),
                    MessageId = table.Column<long>(type: "bigint", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_T_UnsentUser", x => x.UnsentId)
                        .Annotation("SqlServer:Clustered", true);
                    table.ForeignKey(
                        name: "FK_T_UnsentUser_T_UserOfflineMessage_MessageId",
                        column: x => x.MessageId,
                        principalTable: "T_UserOfflineMessage",
                        principalColumn: "MessageId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_T_UnsentUser_MessageId",
                table: "T_UnsentUser",
                column: "MessageId");

            migrationBuilder.CreateIndex(
                name: "IX_T_UnsentUser_UserId",
                table: "T_UnsentUser",
                column: "UserId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "T_UnsentUser");

            migrationBuilder.DropPrimaryKey(
                name: "PK_T_UserOfflineMessage",
                table: "T_UserOfflineMessage");

            migrationBuilder.RenameTable(
                name: "T_UserOfflineMessage",
                newName: "UserOfflineMessage");

            migrationBuilder.RenameColumn(
                name: "CreateTime",
                table: "UserOfflineMessage",
                newName: "SendTime");

            migrationBuilder.AddColumn<bool>(
                name: "IsSent",
                table: "UserOfflineMessage",
                type: "bit",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<long>(
                name: "RecipientId",
                table: "UserOfflineMessage",
                type: "bigint",
                nullable: false,
                defaultValue: 0L);

            migrationBuilder.AddPrimaryKey(
                name: "PK_UserOfflineMessage",
                table: "UserOfflineMessage",
                column: "MessageId")
                .Annotation("SqlServer:Clustered", true);
        }
    }
}
